1. Field of the Invention
This invention relates to the field of computer generated graphics, and in particular to a graphics accelerator chipset with a capability for producing realistic lighting effects.
2. Description of Related Art
Realistic displays of objects are obtained by generating perspective projections with hidden surfaces removed and then applying shading and color patterns to the visible surfaces. The intensity of light that should be seen when a surface is viewed is determined by a shading model. The intensity calculations are based on the optical properties of surfaces, the relative positions of the surfaces, and their orientation with respect to light sources.
Light sources that illuminate an object are of two basic types, light-emitting sources and light-reflecting sources. Light-emitting sources include light bulbs and the sun. Light-reflecting sources are illuminated surfaces of other objects, such as the walls of a room, that are near the object being viewed. A surface that is not directly exposed to a light-emitting source will still be visible if nearby objects are illuminated. The multiple reflections of light from such nearby sources combine to produce a uniform illumination called ambient light.
A shading model for calculating the intensity of light reflected from a surface can be established by considering contributions from the ambient light sources and point sources in the vicinity of the surface. Both of these sources produce light reflections that are scattered in all directions. This scattered light is called diffuse reflection, and it results from the surface roughness. A matte surface produces primarily diffuse reflections, so that the surface appears equally bright from all viewing directions. In addition to diffuse reflection, point sources create highlights, or bright spots, called specular reflection. This highlighting effect is more pronounced on shiny surfaces than on dull surfaces.
Since ambient light is the result of multiple reflections from nearby objects, it can be considered to be of uniform intensity I.sub.s in all directions. When ambient light is reflected from a surface, it produces a uniform illumination of the surface at any viewing position from which the surface is visible. If a surface is exposed to only ambient light, the intensity of the diffuse reflection at any point on the surface may be expressed as EQU I=k.sub.d I.sub.a (1)
where k.sub.d is the reflectivity of the surface. It is assigned a constant value in the interval 0 to 1, according to the reflective properties of the surface. Highly reflective surfaces have a reflectivity near 1.
Rarely are surfaces illuminated with ambient light alone. A shading model that calculates intensities according to the above equation would shade all visible surfaces of an object with the same intensity. More realistic shading is obtained by including the effects of point sources in the shading model.
The calculation of diffuse reflection due to a point source of light is based on Lambert's cosine law, which states that the intensity of the reflected light depends on the angle of illumination. A surface that is perpendicular to the direction of the incident light appears brighter than a surface that is at an angle to the direction of the incoming light. As the angle increased, less of the incident light is reflected by the surface. The orientation of a surface can be described with a unit normal vector N and the direction of the light source can be described with a unit vector L. The angle .theta. between these two vectors is called the angle of incidence, and Lambert's cosine law states that the intensity of reflected light is proportional to cos .theta.. The cos .theta. can be calculated from the dot product of these two unit vectors: EQU cos .theta.=N.multidot.L. (2)
When a surface is illuminated by a point source the angle of incidence is between 0.degree. and 90.degree.. When cos .theta. is negative, the light source is "behind" the surface.
The brightness of an illuminated surface is also dependent on the distance to the light source, since more distant sources are fainter than those that are nearer. If d represents the distance from a light source to a point on the surface, and I.sub.P is the intensity of the source, the intensity of the diffuse reflection at that position on the surface can be modeled as EQU I=k.sub.d I.sub.P (N.multidot.L)/(d+d.sub.0) (3)
where parameter d.sub.0 is a constant that is included to prevent the denominator from approaching zero when d is small. This adaptation of Lambert's cosine law has been found to produce realistic shading of surfaces. Theoretically, the light intensity arriving at a surface is proportional to 1/d.sup.2, where d is the distance from the surface to the point source. However, most light sources are larger than points, and the intensity may be expected to decrease less rapidly. The denominator in the above equation more accurately models the intensity reflections for surfaces at varying distances from a nearby light source.
Total diffuse reflection for a surface illuminated by ambient light and one point source is given by EQU I=k.sub.d I.sub.a+ k.sub.d I.sub.P (N.multidot.L)/(d+d.sub.0).(4)
If more than one point source is to be included in a scene, the above equation is expanded to include terms for the additional light sources.
At certain viewing angles, a shiny surface reflects all incident light, independent of the reflectivity values. This phenomenon, called specular reflection, produces a spot of reflected light that is the same color as the incident light. Normally, objects are illuminated with white light, so that the specular reflection is a bright white spot. For an ideal reflector (perfect mirror), the angle of incidence and the angle of specular reflection are the same. The unit vector R is used to represent the direction for specular reflection. Unit vector V points in the direction of the viewer, and unit vector L points to the light source. Specular reflection with a perfect reflector can only be seen when V and R coincide (i.e. the angle .phi. between V and R is zero).
Real objects exhibit specular reflection over a range of positions about the vector R. Shiny surfaces have a narrow reflection range, and dull surfaces have a wider reflection range. Specular-reflection models must produce the highest intensity in the direction of R, with the intensity decreasing rapidly as the viewing angle .phi. increases.
One method for modeling specular reflection, developed by Phong Bui Tuong and called the Phong model, sets the intensity of specular reflection proportional to cos.sup.n .phi.. The value assigned to n determines the type of surface that is to be viewed. A very shiny surface is modeled with a large value for n (200 or more), and smaller values (down to 1) are used for duller surfaces. For a perfect reflector, n is infinite. A rough surface such as cardboard might be assigned a value near 1.
Specular reflection also depends on the angle of incidence. In general, the intensity increases as the angle of incidence increases. This effect is incorporated into the specular reflection model by making the intensity proportional to a reflection function W(.theta.), so that the complete reflection model is written as EQU I=k.sub.d I.sub.a +[k.sub.d (N.multidot.L)+W(.theta.)cos.sup.n .phi.]I.sub.P /(d+d.sub.0). (5)
The functional form for W(.theta.) depends on the surface material. Some materials, such as glass, exhibit very little specular reflection at smaller angles of incidence but increase the intensity of the specular reflection as .theta. approaches 90.degree.. Some materials have nearly constant specular reflection for all incidence angles, so that W could be assigned a constant value in the interval 0 to 1.
Since V and R are unit vectors in the vieiwng and reflection directions, the cos .phi.=V.multidot.R Also, for many applications, the intensity calculations can be simplified by setting W(.theta.) to a constant value k.sub.s for the surface. The complete intensity model for reflection, due to ambient light and a single point source can then be written as EQU I=k.sub.d I.sub.a +[k.sub.d (N.multidot.L)+k.sub.s (V.multidot.R).sup.n ]I.sub.P /(d+d.sub.0). (6)
In this model, constant values are assigned to parameters k.sub.d, k.sub.s, and d.sub.0 for each illuminated surface. Intensity values for the ambient light and the point sources are set, and values for the unit vectors are established. For each point on an illuminated surface, the relevant dot products are calculated and the intensity of the reflected light determined.
Since an infinite number of intensity points could be generated over the various surfaces in a scene, an effective method for determining the specular intensities at visible surface positions is to trace rays backward from the viewing position to the light source. This technique is referred to as ray tracing.
Starting from the viewing position, the ray passing through each pixel in the view plane is traced back to a surface in the three-dimensional scene. The ray is then reflected backward from this surface to determine whether it came from another surface of from a point source. This backward tracing continues until the ray ends at a light source or passes out of the scene. Each pixel is processed in this way, and the number of rays that must be traced is equal to the number of pixels to be displayed.
After a ray has been processed to determine all specular intensity contributions, the intensity of the corresponding pixel is set. Ray tracing requires considerable computation, but it produces highly realistic results. To enable more extensive use of realistic shading and ray tracing techniques in computer generated graphics, techniques for reducing the computation time for these models are desirable.